import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_page/mine_business/ai/ai_home_menu_page.dart';
import 'package:provider/provider.dart';

import '../../../main_page/provider/ai_bubble_provider.dart';

class FloatingAiMoveView extends StatefulWidget {
  final Function? tapCallBack;
  final Function? closeCallBack;
  final double? bottom;

  const FloatingAiMoveView({
    Key? key,
    this.tapCallBack,
    this.closeCallBack,
    this.bottom,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _FloatingAiMoveViewState();
  }
}

class _FloatingAiMoveViewState extends State<FloatingAiMoveView> {
  double get _adW => 116;
  double get _adH => 112;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: _adW,
      width: _adH,
      child: Stack(
        clipBehavior: Clip.none,
        children: [
          SizedBox(
            height: _adW,
            width: _adH,
            child: GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                if (widget.tapCallBack != null) {
                  widget.tapCallBack?.call();
                } else {
                  Get.to(AiHomeMenuPage());
                }
              },
              child: Image.asset(
                'dialog.gif'.commonImgPath,
                width: _adW,
                height: _adH,
                alignment: Alignment.centerRight,
              ),
            ),
          ),
          Consumer<AIBubbleProvider>(builder: (_, bubble, __) {
            if (bubble.bubbleHint.isEmpty) return SizedBox.shrink();
            return Positioned(
              left: -1,
              top: -30,
              child: GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTapUp: (details) {
                  if (widget.tapCallBack != null) {
                    widget.tapCallBack?.call();
                  } else {
                    Get.to(AiHomeMenuPage());
                  }
                },
                child: Container(
                  padding: EdgeInsets.only(top: 16, bottom: 24, left: 12, right: 12),
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage(
                        'ai_bubble.png'.mineImgPath,
                      ),
                    ),
                  ),
                  child: Text(
                    '${bubble.bubbleHint}',
                    textAlign: TextAlign.center,
                    maxLines: 2,
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 10,
                      fontWeight: FontWeight.w400,
                    ),
                  ),
                ),
              ),
            );
          }),
          if (widget.closeCallBack != null)
            Positioned(
              right: 0,
              top: -8,
              child: GestureDetector(
                onTap: () {
                  widget.closeCallBack?.call();
                },
                behavior: HitTestBehavior.translucent,
                child: Padding(
                  padding: const EdgeInsets.all(8.0).copyWith(right: 0),
                  child: Image.asset(
                    'close_grey.png'.commonImgPath,
                    width: 16,
                  ),
                ),
              ),
            )
        ],
      ),
    );
  }
}
